﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;
using Microsoft.Phone.Controls;
using System.Windows.Navigation;
using RedBit.UserVoice.Services;

namespace SampleApplication
{
    public partial class DetailsPage : PhoneApplicationPage
    {
        private string m_suggestionId = "";
        private string m_forumId = "";

        public DetailsPage()
        {
            InitializeComponent();
        }

        protected override void OnNavigatedTo(NavigationEventArgs e)
        {
            base.OnNavigatedTo(e);

            NavigationContext.QueryString.TryGetValue("suggestionId", out m_suggestionId );
            NavigationContext.QueryString.TryGetValue("forumId", out m_forumId);

            UVSuggestionService.GetSingleSuggestion(m_forumId, m_suggestionId, suggestion => 
                {
                    Deployment.Current.Dispatcher.BeginInvoke(() => this.DataContext = suggestion.Model );
                });
        }

        private void cbCancel_Click(object sender, EventArgs e)
        {
            NavigationService.GoBack();
        }

        private void cbSave_Click(object sender, EventArgs e)
        {

        }

        private const string COMMENT_URL = "/CommentPage.xaml?suggestionId={0}&forumId={1}";
        private void cbComment_Click(object sender, EventArgs e)
        {
            NavigationService.Navigate(new Uri(string.Format(COMMENT_URL, m_suggestionId, m_forumId), UriKind.Relative));
        }
    }
}